import QtQuick 1.1

MyPage {
    id: discoveryPage


    Flickable {
        id: flickArea
        anchors.top: parent.top; anchors.topMargin: 5
        anchors.bottom: toolBar.top; anchors.bottomMargin: 5
        anchors.left: parent.left; anchors.leftMargin: 10
        anchors.right: parent.right; anchors.rightMargin: 10

        contentHeight: contentPage.height
        contentWidth: contentPage.width

        flickableDirection: Flickable.VerticalFlick

        Column {
            id: contentPage
            width: discoveryPage.width - flickArea.anchors.rightMargin - flickArea.anchors.leftMargin
            spacing: 10

            Item {
                id: spacer1
                height: 30
                width: discoveryPage.width
            }

            Row {
                spacing: 20
                anchors.horizontalCenter: parent.horizontalCenter
                Image {
                    id: imgAddContact
                    anchors.verticalCenter: parent.verticalCenter
                    source: "qrc:/qml/images/muc.png"
                }
                Text {
                    id: txtAddContact
                    anchors.verticalCenter: parent.verticalCenter
                    text: qsTr("Multi-user chat:")
                    font.pixelSize: 32
                }
            }

            Item {
                id: spacer11
                height: 20
                width: discoveryPage.width
            }

            Text {
                id: txtJid
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Room:")
                font.pixelSize: 28
            }
            Text {
                id: txtJidExample
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Example: room@conference.server.com")
                color: "gray"
                font.pixelSize: 18
                font.italic: true
            }
            MyTextInput2 {
                id: tiJid
                anchors.horizontalCenter: parent.horizontalCenter
                height: 50
                width: parent.width
                Component.onCompleted: {
                    if( main.invRoomJid != "" ) {
                        tiJid.text = main.invRoomJid
                    }
                }
            }

            Item {
                height: 10
                width: discoveryPage.width
            }


            Text {
                id: txtNickname
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Nickname:")
                font.pixelSize: 28
            }
            MyTextInput2 {
                id: tiNickname
                anchors.horizontalCenter: parent.horizontalCenter
                height: 50
                width: parent.width
                font.pixelSize: 28
                Component.onCompleted: {
                    if( main.invMyNickName != "" ) {
                        tiNickname.text = main.invMyNickName
                    }
                }
            }

            Item {
                id: spacer3
                height: 10
                width: discoveryPage.width
            }

            Text {
                id: txtPassword
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Passowrd:")
                font.pixelSize: 28
            }
            MyTextInput2 {
                id: tiPassword
                anchors.horizontalCenter: parent.horizontalCenter
                height: 50
                width: parent.width
                font.pixelSize: 28
            }

            Item {
                height: 10
                width: discoveryPage.width
            }

            MyCheckBox {
                id: cbAddToRoster
                text: qsTr("bookmark")
            }

            Item {
                height: 10
                width: discoveryPage.width
            }

            Item {
                id: spacer6
                height: 5
                width: discoveryPage.width
            }
        }
    }


    /******************************************/

    ToolBar {
        id: toolBar
        ToolButton {
            id: toolBarButtonRoster
            icon: "qrc:/qml/images/bar_options.png"
            anchors.left: parent.left
            anchors.leftMargin: (0.5*(parent.width/4) - 0.5*toolBarButtonRoster.width)
            onClicked: {
                discoveryPage.closePage( "qrc:/qml/RosterPage.qml" )
            }
            pauseAnim: 500
        }

        ToolButton {
            id: toolBarButtonOptions
            icon: "qrc:/qml/images/bar_ok.png"
            anchors.left: parent.left
            anchors.leftMargin: (3.5*(parent.width/4) - 0.5*toolBarButtonOptions.width)
            onClicked: {
                if ( (tiNickname.text != "") && (tiJid.text != "") )
                {
                    muc.nickName = tiNickname.text
                    if ( tiPassword.text != "" ) {
                        muc.password = tiPassword.text
                    }
                    xmppClient.addMucRoster( tiJid.text, muc.subjectRoom, cbAddToRoster.checked ) //add muc to roster
                    muc.jidRoom = tiJid.text //enter to muc
                    discoveryPage.closePage( "qrc:/qml/RosterPage.qml" )
                    //xmppClient.chatJid = main.invRoomJid
                    main.invRoomJid = ""
                    main.invIniterJid = ""
                }
            }
            pauseAnim: 600
        }
    }
}
